home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xpaint-2.1.1 / image.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  93 lines

  1. #ifndef __IMAGE_H__
  2. #define __IMAGE_H__
  3.  
  4. /* +-------------------------------------------------------------------+ */
  5. /* | Copyright (C) 1993, David Koblas (koblas@netcom.com)              | */
  6. /* |                                                                   | */
  7. /* | Permission to use, copy, modify, and to distribute this software  | */
  8. /* | and its documentation for any purpose is hereby granted without   | */
  9. /* | fee, provided that the above copyright notice appear in all       | */
  10. /* | copies and that both that copyright notice and this permission    | */
  11. /* | notice appear in supporting documentation.  There is no           | */
  12. /* | representations about the suitability of this software for        | */
  13. /* | any purpose.  this software is provided "as is" without express   | */
  14. /* | or implied warranty.                                              | */
  15. /* |                                                                   | */
  16. /* +-------------------------------------------------------------------+ */
  17.  
  18. typedef struct {
  19.     int    refCount;    /* reference count */
  20.  
  21.     /*
  22.     **  Special notes:
  23.     **    if the image isBW then there will be a two entry
  24.     **       colormap BLACK == 0, WHITE == 1
  25.     **    if the image isGrey, then the colormap is 256 entries
  26.     **       BLACK == 0 .. WHITE == 255
  27.     */
  28.     int    isGrey, isBW;    /* simple indicator flags  GreyScale, Black & White */
  29.     /*
  30.     **   number of bytes per pixel (3 for RGB, 2 for 0..256+ cmap, 1 for 0..256 cmap)
  31.     */
  32.     int    scale;
  33.     /*
  34.     **  Colormap entries
  35.     **   rgb rgb rgb [1..size]
  36.     */
  37.     int        cmapPacked;    /* Boolean, is the colormap packed 
  38.                        down to just the used colors */
  39.     int        cmapSize;    /* number of colors in colormap == 0 if no colormap */
  40.     unsigned char    *cmapData;
  41.     /*
  42.     **  Image data
  43.     **   either rgb rgb rgb
  44.     **   or     idx idx idx
  45.     **
  46.     **   if image has colormap, and the size > 256, then
  47.     **     data is pointers to unsigned shorts.
  48.     */
  49.     int        width, height;    /* width, height of image */
  50.     unsigned char    *data;        
  51.     unsigned char    *maskData;
  52.  
  53.     /*
  54.     **  These values are here because the XPM calls are TOO dependant
  55.     **   on X Windows.  They are not, and should not, be used by anything
  56.     **   else.
  57.     */
  58.     unsigned long    sourcePixmap;
  59.     unsigned long    sourceColormap;
  60.     unsigned long    sourceMask;
  61. } Image;
  62.  
  63. #define ImagePixel(image, x, y)                        \
  64.     (((image)->cmapSize == 0)                    \
  65.       ? &((image)->data[(y * (image)->width + x) * 3])        \
  66.       : (((image)->cmapSize > 256)                    \
  67.          ? &((image)->cmapData[((unsigned short *)(image)->data)    \
  68.                 [y * (image)->width + x] * 3])        \
  69.          : &((image)->cmapData[(image)->data[y * (image)->width + x] * 3])))
  70.  
  71. #define ImageSetCmap(image, index, r, g, b) do {        \
  72.             image->cmapData[(index) * 3 + 0] = r;    \
  73.             image->cmapData[(index) * 3 + 1] = g;    \
  74.             image->cmapData[(index) * 3 + 2] = b;    \
  75.         } while (0)
  76.  
  77. Image    *ImageNew(int, int);
  78. Image    *ImageNewGrey(int, int);
  79. Image    *ImageNewBW(int, int);
  80. Image    *ImageNewCmap(int, int, int);
  81. Image    *ImageCompress(Image *, int);
  82. void    ImageDelete(Image *);
  83. void    ImakeMakeMask(Image *);
  84. #ifdef _XtIntrinsic_h
  85. Image    *PixmapToImage(Widget, Pixmap, Colormap);
  86. Boolean    ImageToPixmap(Image *, Widget, Pixmap*, Colormap*);
  87. Boolean    ImageToPixmapCmap(Image *, Widget, Pixmap*, Colormap);
  88. Pixmap  ImageMaskToPixmap(Widget, Image *);
  89. void     PixmapToImageMask(Widget, Image *, Pixmap);
  90. #endif
  91.  
  92. #endif /* __IMAGE_H__ */
  93.